<?php
if( is_admin() ) {

	/* Start of: WordPress Administration */

	function wpsc_st_template_header() {

		global $wpsc_st; ?>
<div class="wrap">
	<div id="icon-tools" class="icon32"><br /></div>
	<h2><?php echo $wpsc_st['menu']; ?></h2>
<?php
	}

	function wpsc_st_template_footer() { ?>
</div>
<?php
	}


	function wpsc_st_empty_dir( $dir ) {

		if( strpos( php_uname(), 'Windows' ) !== FALSE )
			$dir = str_replace( '/', '\\', $dir );
		
		$handle = opendir( $dir );
		if( $handle ) {
			while( ( $file = readdir( $handle ) ) !== false ) {
				if( $file <> '.htaccess' )
					@unlink( $dir . '/' . $file );
			}
		}
		closedir( $handle );

	}

	if( !function_exists( 'wpsc_st_remove_filename_extension' ) ) {

		function wpsc_st_remove_filename_extension( $filename ) {

			$extension = strrchr( $filename, '.' );
			$filename = substr( $filename, 0, -strlen( $extension ) );

			return $filename;

		}

	}

	function wpsc_st_post_statuses() {

		$output = array(
			'publish',
			'pending',
			'draft',
			'auto-draft',
			'future',
			'private',
			'inherit',
			'trash'
		);
		return $output;

	}

	function wpsc_st_pd_options_addons( $options ) {

		$options[] = array( 'aioseop_keywords', __( 'All in One SEO - Keywords', 'wpsc_pd' ) );
		$options[] = array( 'aioseop_description', __( 'All in One SEO - Description', 'wpsc_pd' ) );
		$options[] = array( 'aioseop_title', __( 'All in One SEO - Title', 'wpsc_pd' ) );
		$options[] = array( 'aioseop_titleatr', __( 'All in One SEO - Title Attributes', 'wpsc_pd' ) );
		$options[] = array( 'aioseop_menulabel', __( 'All in One SEO - Menu Label', 'wpsc_pd' ) );
		return $options;

	}
	add_filter( 'wpsc_pd_options_addons', 'wpsc_st_pd_options_addons', null, 1 );

	function wpsc_st_pd_import_addons( $import, $csv_data ) {

		if( function_exists( 'aioseop_get_version' ) ) {
			if( isset( $csv_data['aioseop_keywords'] ) ) {
				$import->csv_aioseop_keywords = array_filter( $csv_data['aioseop_keywords'] );
				$import->log .= "<br />>>> " . __( 'All in One SEO Pack - Keywords has been detected and grouped', 'wpsc_pd' );
			}
			if( isset( $csv_data['aioseop_description'] ) ) {
				$import->csv_aioseop_description = array_filter( $csv_data['aioseop_description'] );
				$import->log .= "<br />>>> " . __( 'All in One SEO Pack - Description has been detected and grouped', 'wpsc_pd' );
			}
			if( isset( $csv_data['aioseop_title'] ) ) {
				$import->csv_aioseop_title = array_filter( $csv_data['aioseop_title'] );
				$import->log .= "<br />>>> " . __( 'All in One SEO Pack - Title has been detected and grouped', 'wpsc_pd' );
			}
			if( isset( $csv_data['aioseop_titleatr'] ) ) {
				$import->csv_aioseop_titleatr = array_filter( $csv_data['aioseop_titleatr'] );
				$import->log .= "<br />>>> " . __( 'All in One SEO Pack - Title Attributes has been detected and grouped', 'wpsc_pd' );
			}
			if( isset( $csv_data['aioseop_menulabel'] ) ) {
				$import->csv_aioseop_menulabel = array_filter( $csv_data['aioseop_menulabel'] );
				$import->log .= "<br />>>> " . __( 'All in One SEO Pack - Menu Label has been detected and grouped', 'wpsc_pd' );
			}
		} else {
			$import->log .= "<br />>>> " . __( 'All in One SEO Pack was not detected, skipping Product meta tags', 'wpsc_pd' );
		}
		return $import;

	}
	add_filter( 'wpsc_pd_import_addons', 'wpsc_st_pd_import_addons', null, 2 );

	function wpsc_st_pd_product_addons( $product, $import, $count ) {

		if( isset( $import->csv_aioseop_keywords[$count] ) )
			$product->aioseop_keywords = $import->csv_aioseop_keywords[$count];
		if( isset( $import->csv_aioseop_description[$count] ) )
			$product->aioseop_description = $import->csv_aioseop_description[$count];
		if( isset( $import->csv_aioseop_title[$count] ) )
			$product->aioseop_title = $import->csv_aioseop_title[$count];
		if( isset( $import->csv_aioseop_titleatr[$count] ) )
			$product->aioseop_titleatr = $import->csv_aioseop_titleatr[$count];
		if( isset( $import->csv_aioseop_menulabel[$count] ) )
			$product->aioseop_menulabel = $import->csv_aioseop_menulabel[$count];
		return $product;

	}
	add_filter( 'wpsc_pd_product_addons', 'wpsc_st_pd_product_addons', null, 3 );

	function wpsc_st_pd_create_product_log_addons( $import, $product ) {

		if( isset( $product->aioseop_keywords ) || isset( $product->aioseop_description ) || isset( $product->aioseop_title ) || isset( $product->aioseop_titleatr ) || isset( $product->aioseop_menulabel ) )
			$import->log .= "<br />>>>>>> " . __( 'Linking All in One SEO Pack meta details', 'wpsc_pd' );
		return $import;

	}
	add_filter( 'wpsc_pd_create_product_log_addons', 'wpsc_st_pd_create_product_log_addons', null, 2 );

	function wpsc_st_pd_merge_product_data_addons( $product_data, $product, $import ) {

		if( $product->ID ) {
			$product_data->aioseop_keywords = get_post_meta( $product->ID, '_aioseop_keywords', true );
			$product_data->aioseop_description = get_post_meta( $product->ID, '_aioseop_description', true );
			$product_data->aioseop_title = get_post_meta( $product->ID, '_aioseop_title', true );
			$product_data->aioseop_titleatr = get_post_meta( $product->ID, '_aioseop_titleatr', true );
			$product_data->aioseop_menulabel = get_post_meta( $product->ID, '_aioseop_menulabel', true );
		}
		return $product_data;

	}
	add_filter( 'wpsc_pd_merge_product_data_addons', 'wpsc_st_pd_merge_product_data_addons', null, 3 );

	function wpsc_st_pd_merge_product_log_addons( $import, $product, $product_data ) {

		if( isset( $product->aioseop_keywords ) && $product->aioseop_keywords || isset( $product->aioseop_description ) && $product->aioseop_description || isset( $product->aioseop_title ) && $product->aioseop_title || isset( $product->aioseop_titleatr ) && $product->aioseop_titleatr || isset( $product->aioseop_menulabel ) && $product->aioseop_menulabel ) {
			if( isset( $product->aioseop_keywords ) ) {
				if( $product_data->aioseop_keywords <> $product->aioseop_keywords )
					$import->log .= "<br />>>>>>> " . __( 'Updating AIOSEO Pack Keywords', 'wpsc_pd' );
			}
			if( isset( $product->aioseop_description ) ) {
				if( $product_data->aioseop_description <> $product->aioseop_description )
					$import->log .= "<br />>>>>>> " . __( 'Updating AIOSEO Pack Description', 'wpsc_pd' );
			}
			if( isset( $product->aioseop_title ) ) {
				if( $product_data->aioseop_title <> $product->aioseop_title )
					$import->log .= "<br />>>>>>> " . __( 'Updating AIOSEO Pack Title', 'wpsc_pd' );
			}
			if( isset( $product->aioseop_titleatr ) ) {
				if( $product_data->aioseop_titleatr <> $product->aioseop_titleatr )
					$import->log .= "<br />>>>>>> " . __( 'Updating AIOSEO Pack Title Atr', 'wpsc_pd' );
			}
			if( isset( $product->aioseop_menulabel ) ) {
				if( $product_data->aioseop_menulabel <> $product->aioseop_menulabel )
					$import->log .= "<br />>>>>>> " . __( 'Updating AIOSEO Pack Menu Label', 'wpsc_pd' );
			}
		}
		return $import;

	}
	add_filter( 'wpsc_pd_merge_product_log_addons', 'wpsc_st_pd_merge_product_log_addons', null, 3 );

	/* End of: WordPress Administration */

}
?>